<?php

defined('SYSPATH') or die('No direct access allowed.');

/**
 * Service User 
 */
class Model_Service_Permission extends Domain_Dao_Permission {

    public $_rep;

    /**
     * 
     */
    public function __construct()
    {
        $o_repository_manager = new Domain_Repositories_RepositoryManager;
        $this->_rep = $o_repository_manager->getPermissionRepository();
    }

    /**
     *
     * @return <type>
     */
    public function load($id)
    {
        return $this->_rep->load($id);
    }

    /**
     *
     * @param <type> $offset
     * @param <type> $limit
     * @param <type> $filter
     * @param <type> $sort
     * @param <type> $count
     * @return <type>
     */
    public function load_all($is_count = false, $offset=null, $limit=null, $filter = null, $sort = null)
    {
        return $this->_rep->load_all($offset, $limit, $filter, $sort, $is_count);
    }

    /**
     *
     * @param Domain_Entities_Entity $o_entity
     * @return <type> 
     */
    public function insert($o_entity)
    {
        return $this->_rep->insert_by($o_entity);
    }

    /**
     *
     * @param Domain_Entities_Entity $o_entity
     * @return <type>
     */
    public function update($o_entity)
    {
        return $this->_rep->update_by($o_entity);
    }

    /**
     *
     * @param <type> $id
     * @return <type> 
     */
    public function delete($id)
    {
        return $this->_rep->delete_by($id);
    }


    public function get_permission_for_cache(){
        $a_result = array();
        $a_per = $this->load_all();
        if (!empty($a_per) && !empty($a_per[0]))
        {
            foreach ($a_per as $o_per) {
                $o_entity_per = $o_per->get_data();
                $s_pc = $o_entity_per->get_Permissioncontroller();
                $o_entity_pc = $s_pc->get_data();
                $o_entity_per->set__Controller($o_entity_pc->getName());
                $o_entity_per->clear_data_foreign_key();
                $a_result[] = $o_entity_per;
            }
        }
        return $a_result;
        
    }
    

}

?>
